﻿using Microsoft.AspNetCore.Mvc.Filters;
using RAP.Web.Libary.Authentication.Attributes;
using System.Threading.Tasks;

namespace RAP.Web.Libary.Controller.Filters
{
    /// <summary>
    /// 检测数据权限的Filter
    /// </summary>
    public class HasDataPowerFilter : IAsyncActionFilter
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task OnActionExecutionAsync ( ActionExecutingContext context, ActionExecutionDelegate next )
        {
            var result = HasDataPowerAttribute.ProcessAttributes( context );
            if ( result != false )
            {
                await next();
            }
            else
            {
                context.Result = await ( context.Controller as IWebController ).ErrorContent( "权限不足！" );
            }
        }
    }
}
